package com.fyx.service.impl;

import com.fyx.entity.*;
import com.fyx.service.IPeakService;
import com.fyx.until.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class PeakServiceImpl implements IPeakService {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public Map activeUser(OnlineUserPeakEntity onlineUserPeakEntity, Pageable pageable) {
        System.out.println(onlineUserPeakEntity);
        String Qtime= DateUtil.timeStamp2Date(String.valueOf(new Date().getTime()/1000),"yyyy-MM-dd");
        Query query = new Query();
        query.skip((pageable.getPageNumber())*pageable.getPageSize());
        query.limit(pageable.getPageSize());
        Criteria criteria = new Criteria();
        if(onlineUserPeakEntity.getQTime()==null){
            criteria.andOperator(Criteria.where("time").gte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))).lte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))+86399));
        }else{
            criteria.andOperator(Criteria.where("time").gte(onlineUserPeakEntity.getQTime().get(0).getTime()/1000).lte(onlineUserPeakEntity.getQTime().get(1).getTime()/1000));
        }
        if(onlineUserPeakEntity.getChannel()==null){
            criteria.orOperator(Criteria.where("channel").exists(false),Criteria.where("channel").is("total"));
        }else {
            criteria.and("channel").is(onlineUserPeakEntity.getChannel());
        }
        query.addCriteria(criteria);
        query.with( Sort.by(Sort.Direction.DESC,new String[]{"time"}));
        List<OnlineUserPeakEntity> list = mongoTemplate.find(query, OnlineUserPeakEntity.class);
        long total = mongoTemplate.count(query, OnlineUserPeakEntity.class);
        //去重
        for (int i = 0; i < list.size() - 1; i++) {
            for (int j = list.size() - 1; j > i; j--) {
                long time =list.get(j).getTime();
                long time1=list.get(i).getTime();
                String quantum = list.get(j).getQuantum();
                String quantum1 = list.get(i).getQuantum();
                if(time==time1&&quantum.equals(quantum1)){
                    list.remove(j);
                    total=total-1;
                }
            }
        }

        //今日数据
        query = new Query();
        criteria = new Criteria();
        if(onlineUserPeakEntity.getQTime()==null){
            criteria.andOperator(Criteria.where("time").gte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))).lte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))+86399));
        }else{
            criteria.andOperator(Criteria.where("time").gte(onlineUserPeakEntity.getQTime().get(0).getTime()/1000).lte(onlineUserPeakEntity.getQTime().get(1).getTime()/1000));
        }
        if(onlineUserPeakEntity.getChannel()==null){
            criteria.orOperator(Criteria.where("channel").exists(false),Criteria.where("channel").is("total"));
        }else {
            criteria.and("channel").is(onlineUserPeakEntity.getChannel());
        }
        query.addCriteria(criteria);
        query.with( Sort.by(Sort.Direction.ASC,new String[]{"time"}));
        List<OnlineUserPeakEntity> todayDataList = mongoTemplate.find(query, OnlineUserPeakEntity.class);
        //去重
        for (int i = 0; i < todayDataList.size() - 1; i++) {
            for (int j = todayDataList.size() - 1; j > i; j--) {
                long time =todayDataList.get(j).getTime();
                long time1=todayDataList.get(i).getTime();
                String quantum = todayDataList.get(j).getQuantum();
                String quantum1 = todayDataList.get(i).getQuantum();
                if(time==time1&&quantum.equals(quantum1)){
                    todayDataList.remove(j);
                }
            }
        }


        int[] todayData = new int[todayDataList.size()];
        for(int x=0;x<todayDataList.size();x++){
            OnlineUserPeakEntity onlineUserPeakEntity1=todayDataList.get(x);
            todayData[x]=onlineUserPeakEntity1.getNum();
        }

        //昨日数据
        query = new Query();
        criteria = new Criteria();
        if(onlineUserPeakEntity.getQTime()==null){
            criteria.andOperator(Criteria.where("time").gte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))-86400).lte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))+86399-24*3600));
        }else{
            criteria.andOperator(Criteria.where("time").gte(onlineUserPeakEntity.getQTime().get(0).getTime()/1000-24*3600).lte(onlineUserPeakEntity.getQTime().get(1).getTime()/1000-24*3600));
        }
        if(onlineUserPeakEntity.getChannel()==null){
            criteria.orOperator(Criteria.where("channel").exists(false),Criteria.where("channel").is("total"));
        }else {
            criteria.and("channel").is(onlineUserPeakEntity.getChannel());
        }
        query.addCriteria(criteria);
        query.with(Sort.by(Sort.Direction.ASC,new String[]{"time"}));
        List<OnlineUserPeakEntity> yestodayDataList=mongoTemplate.find(query, OnlineUserPeakEntity.class);
        //去重
        for (int i = 0; i < yestodayDataList.size() - 1; i++) {
            for (int j = yestodayDataList.size() - 1; j > i; j--) {
                long time =yestodayDataList.get(j).getTime();
                long time1=yestodayDataList.get(i).getTime();
                String quantum = yestodayDataList.get(j).getQuantum();
                String quantum1 = yestodayDataList.get(i).getQuantum();
                if(time==time1&&quantum.equals(quantum1)){
                    yestodayDataList.remove(j);
                }
            }
        }

        int[] yestodayData = new int[yestodayDataList.size()];
        for(int x=0;x<yestodayDataList.size();x++){
            OnlineUserPeakEntity onlineUserPeakEntity1=yestodayDataList.get(x);
            yestodayData[x]=onlineUserPeakEntity1.getNum();
        }

        //3日数据
        query = new Query();
        criteria = new Criteria();
        if(onlineUserPeakEntity.getQTime()==null){
            criteria.andOperator(Criteria.where("time").gte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))-86400*3).lte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))+86399-24*3600*3));
        }else{
            criteria.andOperator(Criteria.where("time").gte(onlineUserPeakEntity.getQTime().get(0).getTime()/1000-24*3600*3).lte(onlineUserPeakEntity.getQTime().get(1).getTime()/1000-24*3600*3));
        }
        if(onlineUserPeakEntity.getChannel()==null){
            criteria.orOperator(Criteria.where("channel").exists(false),Criteria.where("channel").is("total"));
        }else {
            criteria.and("channel").is(onlineUserPeakEntity.getChannel());
        }
        query.addCriteria(criteria);
        query.with(Sort.by(Sort.Direction.ASC,new String[]{"time"}));
        List<OnlineUserPeakEntity> threeDataList=mongoTemplate.find(query, OnlineUserPeakEntity.class);
        //去重
        for (int i = 0; i < threeDataList.size() - 1; i++) {
            for (int j = threeDataList.size() - 1; j > i; j--) {
                long time =threeDataList.get(j).getTime();
                long time1=threeDataList.get(i).getTime();
                String quantum = threeDataList.get(j).getQuantum();
                String quantum1 = threeDataList.get(i).getQuantum();
                if(time==time1&&quantum.equals(quantum1)){
                    threeDataList.remove(j);
                }
            }
        }

        int[] threeData = new int[threeDataList.size()];
        for(int x=0;x<threeDataList.size();x++){
            OnlineUserPeakEntity onlineUserPeakEntity1=threeDataList.get(x);
            threeData[x]=onlineUserPeakEntity1.getNum();
        }

        //7日数据
        query = new Query();
        criteria = new Criteria();
        if(onlineUserPeakEntity.getQTime()==null){
            criteria.andOperator(Criteria.where("time").gte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))-86400*7).lte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))+86399-24*3600*7));
        }else{
            criteria.andOperator(Criteria.where("time").gte(onlineUserPeakEntity.getQTime().get(0).getTime()/1000-24*3600*7).lte(onlineUserPeakEntity.getQTime().get(1).getTime()/1000-24*3600*7));
        }
        if(onlineUserPeakEntity.getChannel()==null){
            criteria.orOperator(Criteria.where("channel").exists(false),Criteria.where("channel").is("total"));
        }else {
            criteria.and("channel").is(onlineUserPeakEntity.getChannel());
        }
        query.addCriteria(criteria);
        query.with(Sort.by(Sort.Direction.ASC,new String[]{"time"}));
        List<OnlineUserPeakEntity> sevenDataList=mongoTemplate.find(query, OnlineUserPeakEntity.class);
        //去重
        for (int i = 0; i < sevenDataList.size() - 1; i++) {
            for (int j = sevenDataList.size() - 1; j > i; j--) {
                long time =sevenDataList.get(j).getTime();
                long time1=sevenDataList.get(i).getTime();
                String quantum = sevenDataList.get(j).getQuantum();
                String quantum1 = sevenDataList.get(i).getQuantum();
                if(time==time1&&quantum.equals(quantum1)){
                    sevenDataList.remove(j);
                }
            }
        }

        int[] sevenData = new int[sevenDataList.size()];
        for(int x=0;x<sevenDataList.size();x++){
            OnlineUserPeakEntity onlineUserPeakEntity1=sevenDataList.get(x);
            sevenData[x]=onlineUserPeakEntity1.getNum();
        }

        List<OnlineUserPeakEntity> xDataList = new ArrayList<>();

        int xDataSize=0;
        xDataSize=yestodayDataList.size();
        xDataList.addAll(yestodayDataList);
        String[] xData = new String[xDataSize];
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        for(int x=0;x<xDataList.size();x++){
            OnlineUserPeakEntity onlineUserPeakEntity1=xDataList.get(x);
            String dateStr=null;
            if(onlineUserPeakEntity.getQTime()==null){
                Date date = new Date();
                dateStr = sdf.format(date);
            }else{
                long time =onlineUserPeakEntity1.getTime()+24*3600;
                Date date = new Date(time*1000);
                dateStr = sdf.format(date);
            }
            xData[x]=dateStr +" " +onlineUserPeakEntity1.getQuantum();
        }


        Map map =new HashMap();
        map.put("content",list);
        map.put("totalElements",total);

        Map yDataMap = new HashMap();
        yDataMap.put("todayData",todayData);
        yDataMap.put("yestodayData",yestodayData);
        yDataMap.put("threeData",threeData);
        yDataMap.put("sevenData",sevenData);

        map.put("chartData",yDataMap);
        map.put("xData",xData);
        return map;
    }

    @Override
    public Map addUser(AddUserPeakEntity addUserPeakEntity, Pageable pageable) {
        System.out.println(addUserPeakEntity);
        String Qtime= DateUtil.timeStamp2Date(String.valueOf(new Date().getTime()/1000),"yyyy-MM-dd");
        Query query = new Query();
        query.skip((pageable.getPageNumber())*pageable.getPageSize());
        query.limit(pageable.getPageSize());
        Criteria criteria = new Criteria();
        if(addUserPeakEntity.getQTime()==null){
            criteria.andOperator(Criteria.where("time").gte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))).lte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))+86399));
        }else{
            criteria.andOperator(Criteria.where("time").gte(addUserPeakEntity.getQTime().get(0).getTime()/1000).lte(addUserPeakEntity.getQTime().get(1).getTime()/1000));
        }
        if(addUserPeakEntity.getChannel()==null){
            criteria.orOperator(Criteria.where("channel").exists(false),Criteria.where("channel").is("total"));
        }else {
            criteria.and("channel").is(addUserPeakEntity.getChannel());
        }
        query.addCriteria(criteria);
        query.with(Sort.by(Sort.Direction.DESC,new String[]{"time"}));
        System.out.println(query);
        List<AddUserPeakEntity> list = mongoTemplate.find(query, AddUserPeakEntity.class);
        long total = mongoTemplate.count(query, AddUserPeakEntity.class);
        //去重
        for (int i = 0; i < list.size() - 1; i++) {
            for (int j = list.size() - 1; j > i; j--) {
                long time =list.get(j).getTime();
                long time1=list.get(i).getTime();
                String quantum = list.get(j).getQuantum();
                String quantum1 = list.get(i).getQuantum();
                if(time==time1&&quantum.equals(quantum1)){
                    list.remove(j);
                    total=total-1;
                }
            }
        }

        //今日数据
        query = new Query();
        criteria = new Criteria();
        if(addUserPeakEntity.getQTime()==null){
            criteria.andOperator(Criteria.where("time").gte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))).lte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))+86399));
        }else{
            criteria.andOperator(Criteria.where("time").gte(addUserPeakEntity.getQTime().get(0).getTime()/1000).lte(addUserPeakEntity.getQTime().get(1).getTime()/1000));
        }
        if(addUserPeakEntity.getChannel()==null){
            criteria.orOperator(Criteria.where("channel").exists(false),Criteria.where("channel").is("total"));
        }else {
            criteria.and("channel").is(addUserPeakEntity.getChannel());
        }
        query.addCriteria(criteria);
        query.with(Sort.by(Sort.Direction.ASC,new String[]{"time"}));
        List<AddUserPeakEntity> todayDataList = mongoTemplate.find(query, AddUserPeakEntity.class);
        //去重
        for (int i = 0; i < todayDataList.size() - 1; i++) {
            for (int j = todayDataList.size() - 1; j > i; j--) {
                long time =todayDataList.get(j).getTime();
                long time1=todayDataList.get(i).getTime();
                String quantum = todayDataList.get(j).getQuantum();
                String quantum1 = todayDataList.get(i).getQuantum();
                if(time==time1&&quantum.equals(quantum1)){
                    todayDataList.remove(j);
                }
            }
        }

        int[] todayData = new int[todayDataList.size()];
        for(int x=0;x<todayDataList.size();x++){
            AddUserPeakEntity AddUserPeakEntity1=todayDataList.get(x);
            todayData[x]=AddUserPeakEntity1.getNum();
        }


        //昨日数据
        query = new Query();
        criteria = new Criteria();
        if(addUserPeakEntity.getQTime()==null){
            criteria.andOperator(Criteria.where("time").gte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))-86400).lte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))+86399-24*3600));
        }else{
            criteria.andOperator(Criteria.where("time").gte(addUserPeakEntity.getQTime().get(0).getTime()/1000-24*3600).lte(addUserPeakEntity.getQTime().get(1).getTime()/1000-24*3600));
        }
        if(addUserPeakEntity.getChannel()==null){
            criteria.orOperator(Criteria.where("channel").exists(false),Criteria.where("channel").is("total"));
        }else {
            criteria.and("channel").is(addUserPeakEntity.getChannel());
        }
        query.addCriteria(criteria);
        query.with(Sort.by(Sort.Direction.ASC,new String[]{"time"}));
        List<AddUserPeakEntity> yestodayDataList=mongoTemplate.find(query, AddUserPeakEntity.class);
        //去重
        for (int i = 0; i < yestodayDataList.size() - 1; i++) {
            for (int j = yestodayDataList.size() - 1; j > i; j--) {
                long time =yestodayDataList.get(j).getTime();
                long time1=yestodayDataList.get(i).getTime();
                String quantum = yestodayDataList.get(j).getQuantum();
                String quantum1 = yestodayDataList.get(i).getQuantum();
                if(time==time1&&quantum.equals(quantum1)){
                    yestodayDataList.remove(j);
                }
            }
        }

        int[] yestodayData = new int[yestodayDataList.size()];
        for(int x=0;x<yestodayDataList.size();x++){
            AddUserPeakEntity AddUserPeakEntity1=yestodayDataList.get(x);
            yestodayData[x]=AddUserPeakEntity1.getNum();
        }


        //3日数据
        query = new Query();
        criteria = new Criteria();
        if(addUserPeakEntity.getQTime()==null){
            criteria.andOperator(Criteria.where("time").gte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))-86400*3).lte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))+86399-24*3600*3));
        }else{
            criteria.andOperator(Criteria.where("time").gte(addUserPeakEntity.getQTime().get(0).getTime()/1000-24*3600*3).lte(addUserPeakEntity.getQTime().get(1).getTime()/1000-24*3600*3));
        }
        if(addUserPeakEntity.getChannel()==null){
            criteria.orOperator(Criteria.where("channel").exists(false),Criteria.where("channel").is("total"));
        }else {
            criteria.and("channel").is(addUserPeakEntity.getChannel());
        }
        query.addCriteria(criteria);
        query.with(Sort.by(Sort.Direction.ASC,new String[]{"time"}));
        List<AddUserPeakEntity> threeDataList=mongoTemplate.find(query, AddUserPeakEntity.class);
        //去重
        for (int i = 0; i < threeDataList.size() - 1; i++) {
            for (int j = threeDataList.size() - 1; j > i; j--) {
                long time =threeDataList.get(j).getTime();
                long time1=threeDataList.get(i).getTime();
                String quantum = threeDataList.get(j).getQuantum();
                String quantum1 = threeDataList.get(i).getQuantum();
                if(time==time1&&quantum.equals(quantum1)){
                    threeDataList.remove(j);
                }
            }
        }

        int[] threeData = new int[threeDataList.size()];
        for(int x=0;x<threeDataList.size();x++){
            AddUserPeakEntity AddUserPeakEntity1=threeDataList.get(x);
            threeData[x]=AddUserPeakEntity1.getNum();
        }


        //7日数据
        query = new Query();
        criteria = new Criteria();
        if(addUserPeakEntity.getQTime()==null){
            criteria.andOperator(Criteria.where("time").gte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))-86400*7).lte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))+86399-24*3600*7));
        }else{
            criteria.andOperator(Criteria.where("time").gte(addUserPeakEntity.getQTime().get(0).getTime()/1000-24*3600*7).lte(addUserPeakEntity.getQTime().get(1).getTime()/1000-24*3600*7));
        }
        if(addUserPeakEntity.getChannel()==null){
            criteria.orOperator(Criteria.where("channel").exists(false),Criteria.where("channel").is("total"));
        }else {
            criteria.and("channel").is(addUserPeakEntity.getChannel());
        }
        query.addCriteria(criteria);
        query.with(Sort.by(Sort.Direction.ASC,new String[]{"time"}));
        List<AddUserPeakEntity> sevenDataList=mongoTemplate.find(query, AddUserPeakEntity.class);
        //去重
        for (int i = 0; i < sevenDataList.size() - 1; i++) {
            for (int j = sevenDataList.size() - 1; j > i; j--) {
                long time =sevenDataList.get(j).getTime();
                long time1=sevenDataList.get(i).getTime();
                String quantum = sevenDataList.get(j).getQuantum();
                String quantum1 = sevenDataList.get(i).getQuantum();
                if(time==time1&&quantum.equals(quantum1)){
                    sevenDataList.remove(j);
                }
            }
        }

        int[] sevenData = new int[sevenDataList.size()];
        for(int x=0;x<sevenDataList.size();x++){
            AddUserPeakEntity AddUserPeakEntity1=sevenDataList.get(x);
            sevenData[x]=AddUserPeakEntity1.getNum();
        }

        List<AddUserPeakEntity> xDataList = new ArrayList<>();

        int xDataSize=0;
        xDataSize=yestodayDataList.size();
        xDataList.addAll(yestodayDataList);
        String[] xData = new String[xDataSize];
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        for(int x=0;x<xDataList.size();x++){
            AddUserPeakEntity addUserPeakEntity1=xDataList.get(x);
            String dateStr=null;
            if(addUserPeakEntity.getQTime()==null){
                Date date = new Date();
                dateStr = sdf.format(date);
            }else{
                long time =addUserPeakEntity1.getTime()+24*3600;
                Date date = new Date(time*1000);
                dateStr = sdf.format(date);
            }
            xData[x]=dateStr +" " +addUserPeakEntity1.getQuantum();
        }

        Map map =new HashMap();
        map.put("content",list);
        map.put("totalElements",total);

        Map yDataMap = new HashMap();
        yDataMap.put("todayData",todayData);
        yDataMap.put("yestodayData",yestodayData);
        yDataMap.put("threeData",threeData);
        yDataMap.put("sevenData",sevenData);

        map.put("chartData",yDataMap);
        map.put("xData",xData);
        return map;
    }

    @Override
    public Map onlineUserPeak(ActiveUserEntity activeUserEntity, Pageable pageable) {
        String Qtime= DateUtil.timeStamp2Date(String.valueOf(new Date().getTime()/1000),"yyyy-MM-dd");
        Query query = new Query();
        query.skip((pageable.getPageNumber())*pageable.getPageSize());
        query.limit(pageable.getPageSize());
        Criteria criteria = new Criteria();
        if(activeUserEntity.getQTime()==null){
            criteria.andOperator(Criteria.where("time").gte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))).lte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))+86399));
        }else{
            criteria.andOperator(Criteria.where("time").gte(activeUserEntity.getQTime().get(0).getTime()/1000).lte(activeUserEntity.getQTime().get(1).getTime()/1000));
        }
        if(activeUserEntity.getChannel()==null){
            criteria.orOperator(Criteria.where("channel").exists(false),Criteria.where("channel").is("total"));
        }else {
            criteria.and("channel").is(activeUserEntity.getChannel());
        }
        query.addCriteria(criteria);
        query.with(Sort.by(Sort.Direction.DESC,new String[]{"time"}));
        List<ActiveUserEntity> list = mongoTemplate.find(query, ActiveUserEntity.class);
        long total = mongoTemplate.count(query, ActiveUserEntity.class);
        //去重
        for (int i = 0; i < list.size() - 1; i++) {
            for (int j = list.size() - 1; j > i; j--) {
                long time =list.get(j).getTime();
                long time1=list.get(i).getTime();
                String quantum = list.get(j).getQuantum();
                String quantum1 = list.get(i).getQuantum();
                if(time==time1&&quantum.equals(quantum1)){
                    list.remove(j);
                    total=total-1;
                }
            }
        }

        //今日数据
        query = new Query();
        criteria = new Criteria();
        if(activeUserEntity.getQTime()==null){
            criteria.andOperator(Criteria.where("time").gte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))).lte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))+86399));
        }else{
            criteria.andOperator(Criteria.where("time").gte(activeUserEntity.getQTime().get(0).getTime()/1000).lte(activeUserEntity.getQTime().get(1).getTime()/1000));
        }
        if(activeUserEntity.getChannel()==null){
            criteria.orOperator(Criteria.where("channel").exists(false),Criteria.where("channel").is("total"));
        }else {
            criteria.and("channel").is(activeUserEntity.getChannel());
        }
        query.addCriteria(criteria);
        query.with(Sort.by(Sort.Direction.ASC,new String[]{"time"}));
        List<ActiveUserEntity> todayDataList = mongoTemplate.find(query, ActiveUserEntity.class);
        //去重
        for (int i = 0; i < todayDataList.size() - 1; i++) {
            for (int j = todayDataList.size() - 1; j > i; j--) {
                long time =todayDataList.get(j).getTime();
                long time1=todayDataList.get(i).getTime();
                String quantum = todayDataList.get(j).getQuantum();
                String quantum1 = todayDataList.get(i).getQuantum();
                if(time==time1&&quantum.equals(quantum1)){
                    todayDataList.remove(j);
                }
            }
        }

        int[] todayData = new int[todayDataList.size()];

        for(int x=0;x<todayDataList.size();x++){
            ActiveUserEntity activeUserEntity1=todayDataList.get(x);
            todayData[x]=activeUserEntity1.getNum();
        }

        //昨日数据
        query = new Query();
        criteria = new Criteria();
        if(activeUserEntity.getQTime()==null){
            criteria.andOperator(Criteria.where("time").gte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))-86400).lte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))+86399-24*3600));
        }else{
            criteria.andOperator(Criteria.where("time").gte(activeUserEntity.getQTime().get(0).getTime()/1000-24*3600).lte(activeUserEntity.getQTime().get(1).getTime()/1000-24*3600));
        }
        if(activeUserEntity.getChannel()==null){
            criteria.orOperator(Criteria.where("channel").exists(false),Criteria.where("channel").is("total"));
        }else {
            criteria.and("channel").is(activeUserEntity.getChannel());
        }
        query.addCriteria(criteria);
        query.with(Sort.by(Sort.Direction.ASC,new String[]{"time"}));
        List<ActiveUserEntity> yestodayDataList=mongoTemplate.find(query, ActiveUserEntity.class);
        //去重
        for (int i = 0; i < yestodayDataList.size() - 1; i++) {
            for (int j = yestodayDataList.size() - 1; j > i; j--) {
                long time =yestodayDataList.get(j).getTime();
                long time1=yestodayDataList.get(i).getTime();
                String quantum = yestodayDataList.get(j).getQuantum();
                String quantum1 = yestodayDataList.get(i).getQuantum();
                if(time==time1&&quantum.equals(quantum1)){
                    yestodayDataList.remove(j);
                }
            }
        }

        int[] yestodayData = new int[yestodayDataList.size()];
        for(int x=0;x<yestodayDataList.size();x++){
            ActiveUserEntity activeUserEntity1=yestodayDataList.get(x);
            yestodayData[x]=activeUserEntity1.getNum();
        }

        //3日数据
        query = new Query();
        criteria = new Criteria();
        if(activeUserEntity.getQTime()==null){
            criteria.andOperator(Criteria.where("time").gte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))-86400*3).lte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))+86399-24*3600*3));
        }else{
            criteria.andOperator(Criteria.where("time").gte(activeUserEntity.getQTime().get(0).getTime()/1000-24*3600*3).lte(activeUserEntity.getQTime().get(1).getTime()/1000-24*3600*3));
        }
        if(activeUserEntity.getChannel()==null){
            criteria.orOperator(Criteria.where("channel").exists(false),Criteria.where("channel").is("total"));
        }else {
            criteria.and("channel").is(activeUserEntity.getChannel());
        }
        query.addCriteria(criteria);
        query.with(Sort.by(Sort.Direction.ASC,new String[]{"time"}));
        List<ActiveUserEntity> threeDataList=mongoTemplate.find(query, ActiveUserEntity.class);
        //去重
        for (int i = 0; i < threeDataList.size() - 1; i++) {
            for (int j = threeDataList.size() - 1; j > i; j--) {
                long time =threeDataList.get(j).getTime();
                long time1=threeDataList.get(i).getTime();
                String quantum = threeDataList.get(j).getQuantum();
                String quantum1 = threeDataList.get(i).getQuantum();
                if(time==time1&&quantum.equals(quantum1)){
                    threeDataList.remove(j);
                }
            }
        }

        int[] threeData = new int[threeDataList.size()];
        for(int x=0;x<threeDataList.size();x++){
            ActiveUserEntity activeUserEntity1=threeDataList.get(x);
            threeData[x]=activeUserEntity1.getNum();
        }

        //7日数据
        query = new Query();
        criteria = new Criteria();
        if(activeUserEntity.getQTime()==null){
            criteria.andOperator(Criteria.where("time").gte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))-86400*7).lte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))+86399-24*3600*7));
        }else{
            criteria.andOperator(Criteria.where("time").gte(activeUserEntity.getQTime().get(0).getTime()/1000-24*3600*7).lte(activeUserEntity.getQTime().get(1).getTime()/1000-24*3600*7));
        }
        if(activeUserEntity.getChannel()==null){
            criteria.orOperator(Criteria.where("channel").exists(false),Criteria.where("channel").is("total"));
        }else {
            criteria.and("channel").is(activeUserEntity.getChannel());
        }
        query.addCriteria(criteria);
        query.with(Sort.by(Sort.Direction.ASC,new String[]{"time"}));
        List<ActiveUserEntity> sevenDataList=mongoTemplate.find(query, ActiveUserEntity.class);
        //去重
        for (int i = 0; i < sevenDataList.size() - 1; i++) {
            for (int j = sevenDataList.size() - 1; j > i; j--) {
                long time =sevenDataList.get(j).getTime();
                long time1=sevenDataList.get(i).getTime();
                String quantum = sevenDataList.get(j).getQuantum();
                String quantum1 = sevenDataList.get(i).getQuantum();
                if(time==time1&&quantum.equals(quantum1)){
                    sevenDataList.remove(j);
                }
            }
        }

        int[] sevenData = new int[sevenDataList.size()];
        for(int x=0;x<sevenDataList.size();x++){
            ActiveUserEntity activeUserEntity1=sevenDataList.get(x);
            sevenData[x]=activeUserEntity1.getNum();
        }

        List<ActiveUserEntity> xDataList = new ArrayList<>();

        int xDataSize=0;
        xDataSize=yestodayDataList.size();
        xDataList.addAll(yestodayDataList);
        String[] xData = new String[xDataSize];
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        for(int x=0;x<xDataList.size();x++){
            ActiveUserEntity activeUserEntity1=xDataList.get(x);
            String dateStr=null;
            if(activeUserEntity.getQTime()==null){
                Date date = new Date();
                dateStr = sdf.format(date);
            }else{
                long time =activeUserEntity1.getTime()+24*3600;
                Date date = new Date(time*1000);
                dateStr = sdf.format(date);
            }
            xData[x]=dateStr +" " +activeUserEntity1.getQuantum();
        }


        Map map =new HashMap();
        map.put("content",list);
        map.put("totalElements",total);

        Map yDataMap = new HashMap();
        yDataMap.put("todayData",todayData);
        yDataMap.put("yestodayData",yestodayData);
        yDataMap.put("threeData",threeData);
        yDataMap.put("sevenData",sevenData);

        map.put("chartData",yDataMap);
        map.put("xData",xData);
        return map;
    }

    @Override
    public Map payUser(PayUserEntity payUserEntity, Pageable pageable) {
        String Qtime= DateUtil.timeStamp2Date(String.valueOf(new Date().getTime()/1000),"yyyy-MM-dd");
        Query query = new Query();
        query.skip((pageable.getPageNumber())*pageable.getPageSize());
        query.limit(pageable.getPageSize());
        Criteria criteria = new Criteria();

        if(payUserEntity.getQTime()==null){
            criteria.andOperator(Criteria.where("time").gte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))).lte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))+86399));
        }else{
            criteria.andOperator(Criteria.where("time").gte(payUserEntity.getQTime().get(0).getTime()/1000).lte(payUserEntity.getQTime().get(1).getTime()/1000));
        }
        if(payUserEntity.getChannel()==null){
            criteria.orOperator(Criteria.where("channel").exists(false),Criteria.where("channel").is("total"));
        }else {
            criteria.and("channel").is(payUserEntity.getChannel());
        }
        query.addCriteria(criteria);
        query.with(Sort.by(Sort.Direction.DESC,new String[]{"time"}));

        List<PayUserEntity> list = mongoTemplate.find(query, PayUserEntity.class);
        long total = mongoTemplate.count(query, PayUserEntity.class);

        //去重
        for (int i = 0; i < list.size() - 1; i++) {
            for (int j = list.size() - 1; j > i; j--) {
                long time =list.get(j).getTime();
                long time1=list.get(i).getTime();
                String quantum = list.get(j).getQuantum();
                String quantum1 = list.get(i).getQuantum();
                if(time==time1&&quantum.equals(quantum1)){
                    list.remove(j);
                    total=total-1;
                }
            }
        }

        //今日数据
        query = new Query();
        criteria = new Criteria();
        if(payUserEntity.getQTime()==null){
            criteria.andOperator(Criteria.where("time").gte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))).lte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))+86399));
        }else{
            criteria.andOperator(Criteria.where("time").gte(payUserEntity.getQTime().get(0).getTime()/1000).lte(payUserEntity.getQTime().get(1).getTime()/1000));
        }
        if(payUserEntity.getChannel()==null){
            criteria.orOperator(Criteria.where("channel").exists(false),Criteria.where("channel").is("total"));
        }else {
            criteria.and("channel").is(payUserEntity.getChannel());
        }
        query.addCriteria(criteria);
        query.with(Sort.by(Sort.Direction.ASC,new String[]{"time"}));
        List<PayUserEntity> todayDataList = mongoTemplate.find(query, PayUserEntity.class);
        //去重
        for (int i = 0; i < todayDataList.size() - 1; i++) {
            for (int j = todayDataList.size() - 1; j > i; j--) {
                long time =todayDataList.get(j).getTime();
                long time1=todayDataList.get(i).getTime();
                String quantum = todayDataList.get(j).getQuantum();
                String quantum1 = todayDataList.get(i).getQuantum();
                if(time==time1&&quantum.equals(quantum1)){
                    todayDataList.remove(j);
                }
            }
        }

        double[] todayData = new double[todayDataList.size()];

        for(int x=0;x<todayDataList.size();x++){
            PayUserEntity payUserEntity1=todayDataList.get(x);
            todayData[x]=payUserEntity1.getAmount()/100;
        }

        //昨日数据
        query = new Query();
        criteria = new Criteria();
        if(payUserEntity.getQTime()==null){
            criteria.andOperator(Criteria.where("time").gte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))-86400).lte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))+86399-24*3600));
        }else{
            criteria.andOperator(Criteria.where("time").gte(payUserEntity.getQTime().get(0).getTime()/1000-24*3600).lte(payUserEntity.getQTime().get(1).getTime()/1000-24*3600));
        }
        if(payUserEntity.getChannel()==null){
            criteria.orOperator(Criteria.where("channel").exists(false),Criteria.where("channel").is("total"));
        }else {
            criteria.and("channel").is(payUserEntity.getChannel());
        }
        query.addCriteria(criteria);
        query.with(Sort.by(Sort.Direction.ASC,new String[]{"time"}));
        List<PayUserEntity> yestodayDataList=mongoTemplate.find(query, PayUserEntity.class);
        //去重
        for (int i = 0; i < yestodayDataList.size() - 1; i++) {
            for (int j = yestodayDataList.size() - 1; j > i; j--) {
                long time =yestodayDataList.get(j).getTime();
                long time1=yestodayDataList.get(i).getTime();
                String quantum = yestodayDataList.get(j).getQuantum();
                String quantum1 = yestodayDataList.get(i).getQuantum();
                if(time==time1&&quantum.equals(quantum1)){
                    yestodayDataList.remove(j);
                }
            }
        }

        double[] yestodayData = new double[yestodayDataList.size()];
        for(int x=0;x<yestodayDataList.size();x++){
            PayUserEntity payUserEntity1=yestodayDataList.get(x);
            yestodayData[x]=payUserEntity1.getAmount()/100;
        }

        //3日数据
        query = new Query();
        criteria = new Criteria();
        if(payUserEntity.getQTime()==null){
            criteria.andOperator(Criteria.where("time").gte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))-86400*3).lte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))+86399-24*3600*3));
        }else{
            criteria.andOperator(Criteria.where("time").gte(payUserEntity.getQTime().get(0).getTime()/1000-24*3600*3).lte(payUserEntity.getQTime().get(1).getTime()/1000-24*3600*3));
        }
        if(payUserEntity.getChannel()==null){
            criteria.orOperator(Criteria.where("channel").exists(false),Criteria.where("channel").is("total"));
        }else {
            criteria.and("channel").is(payUserEntity.getChannel());
        }
        query.addCriteria(criteria);
        query.with(Sort.by(Sort.Direction.ASC,new String[]{"time"}));
        List<PayUserEntity> threeDataList=mongoTemplate.find(query, PayUserEntity.class);
        //去重
        for (int i = 0; i < threeDataList.size() - 1; i++) {
            for (int j = threeDataList.size() - 1; j > i; j--) {
                long time =threeDataList.get(j).getTime();
                long time1=threeDataList.get(i).getTime();
                String quantum = threeDataList.get(j).getQuantum();
                String quantum1 = threeDataList.get(i).getQuantum();
                if(time==time1&&quantum.equals(quantum1)){
                    threeDataList.remove(j);
                }
            }
        }

        double[] threeData = new double[threeDataList.size()];
        for(int x=0;x<threeDataList.size();x++){
            PayUserEntity payUserEntity1=threeDataList.get(x);
            threeData[x]=payUserEntity1.getAmount()/100;
        }

        //7日数据
        query = new Query();
        criteria = new Criteria();
        if(payUserEntity.getQTime()==null){
            criteria.andOperator(Criteria.where("time").gte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))-86400*7).lte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))+86399-24*3600*7));
        }else{
            criteria.andOperator(Criteria.where("time").gte(payUserEntity.getQTime().get(0).getTime()/1000-24*3600*7).lte(payUserEntity.getQTime().get(1).getTime()/1000-24*3600*7));
        }
        if(payUserEntity.getChannel()==null){
            criteria.orOperator(Criteria.where("channel").exists(false),Criteria.where("channel").is("total"));
        }else {
            criteria.and("channel").is(payUserEntity.getChannel());
        }
        query.addCriteria(criteria);
        query.with(Sort.by(Sort.Direction.ASC,new String[]{"time"}));
        List<PayUserEntity> sevenDataList=mongoTemplate.find(query, PayUserEntity.class);
        //去重
        for (int i = 0; i < sevenDataList.size() - 1; i++) {
            for (int j = sevenDataList.size() - 1; j > i; j--) {
                long time =sevenDataList.get(j).getTime();
                long time1=sevenDataList.get(i).getTime();
                String quantum = sevenDataList.get(j).getQuantum();
                String quantum1 = sevenDataList.get(i).getQuantum();
                if(time==time1&&quantum.equals(quantum1)){
                    sevenDataList.remove(j);
                }
            }
        }

        double[] sevenData = new double[sevenDataList.size()];
        for(int x=0;x<sevenDataList.size();x++){
            PayUserEntity payUserEntity1=sevenDataList.get(x);
            sevenData[x]=payUserEntity1.getAmount()/100;
        }

        List<PayUserEntity> xDataList = new ArrayList<>();

        int xDataSize=0;
        xDataSize=yestodayDataList.size();
        xDataList.addAll(yestodayDataList);
        String[] xData = new String[xDataSize];
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        for(int x=0;x<xDataList.size();x++){
            PayUserEntity payUserEntity1=xDataList.get(x);
            String dateStr=null;
            if(payUserEntity.getQTime()==null){
                Date date = new Date();
                dateStr = sdf.format(date);
            }else{
                long time =payUserEntity1.getTime()+24*3600;
                Date date = new Date(time*1000);
                dateStr = sdf.format(date);
            }
            xData[x]=dateStr +" " +payUserEntity1.getQuantum();
        }

        Map map =new HashMap();
        map.put("content",list);
        map.put("totalElements",total);

        Map yDataMap = new HashMap();
        yDataMap.put("todayData",todayData);
        yDataMap.put("yestodayData",yestodayData);
        yDataMap.put("threeData",threeData);
        yDataMap.put("sevenData",sevenData);

        map.put("chartData",yDataMap);
        map.put("xData",xData);

        return map;
    }

    @Override
    public Map rechargeUser(RechargeUserPeakEntity rechargeUserPeakEntity, Pageable pageable) {
        String Qtime= DateUtil.timeStamp2Date(String.valueOf(new Date().getTime()/1000),"yyyy-MM-dd");
        Query query = new Query();
        query.skip((pageable.getPageNumber())*pageable.getPageSize());
        query.limit(pageable.getPageSize());
        Criteria criteria = new Criteria();
        if(rechargeUserPeakEntity.getQTime()==null){
            criteria.andOperator(Criteria.where("time").gte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))).lte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))+86399));
        }else{
            criteria.andOperator(Criteria.where("time").gte(rechargeUserPeakEntity.getQTime().get(0).getTime()/1000).lte(rechargeUserPeakEntity.getQTime().get(1).getTime()/1000));
        }
        if(rechargeUserPeakEntity.getChannel()==null){
            criteria.orOperator(Criteria.where("channel").exists(false),Criteria.where("channel").is("total"));
        }else {
            criteria.and("channel").is(rechargeUserPeakEntity.getChannel());
        }
        query.addCriteria(criteria);
        query.with(Sort.by(Sort.Direction.DESC,new String[]{"time"}));
        List<RechargeUserPeakEntity> list = mongoTemplate.find(query, RechargeUserPeakEntity.class);
        long total = mongoTemplate.count(query, RechargeUserPeakEntity.class);
        //去重
        for (int i = 0; i < list.size() - 1; i++) {
            for (int j = list.size() - 1; j > i; j--) {
                long time =list.get(j).getTime();
                long time1=list.get(i).getTime();
                String quantum = list.get(j).getQuantum();
                String quantum1 = list.get(i).getQuantum();
                if(time==time1&&quantum.equals(quantum1)){
                    list.remove(j);
                    total=total-1;
                }
            }
        }

        //今日数据
        query = new Query();
        criteria = new Criteria();
        if(rechargeUserPeakEntity.getQTime()==null){
            criteria.andOperator(Criteria.where("time").gte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))).lte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))+86399));
        }else{
            criteria.andOperator(Criteria.where("time").gte(rechargeUserPeakEntity.getQTime().get(0).getTime()/1000).lte(rechargeUserPeakEntity.getQTime().get(1).getTime()/1000));
        }
        if(rechargeUserPeakEntity.getChannel()==null){
            criteria.orOperator(Criteria.where("channel").exists(false),Criteria.where("channel").is("total"));
        }else {
            criteria.and("channel").is(rechargeUserPeakEntity.getChannel());
        }
        query.addCriteria(criteria);
        query.with(Sort.by(Sort.Direction.ASC,new String[]{"time"}));
        List<RechargeUserPeakEntity> todayDataList = mongoTemplate.find(query, RechargeUserPeakEntity.class);
        //去重
        for (int i = 0; i < todayDataList.size() - 1; i++) {
            for (int j = todayDataList.size() - 1; j > i; j--) {
                long time =todayDataList.get(j).getTime();
                long time1=todayDataList.get(i).getTime();
                String quantum = todayDataList.get(j).getQuantum();
                String quantum1 = todayDataList.get(i).getQuantum();
                if(time==time1&&quantum.equals(quantum1)){
                    todayDataList.remove(j);
                }
            }
        }


        int[] todayData = new int[todayDataList.size()];
        for(int x=0;x<todayDataList.size();x++){
            RechargeUserPeakEntity rechargeUserPeakEntity1=todayDataList.get(x);
            todayData[x]=rechargeUserPeakEntity1.getNum();
        }

        //昨日数据
        query = new Query();
        criteria = new Criteria();
        if(rechargeUserPeakEntity.getQTime()==null){
            criteria.andOperator(Criteria.where("time").gte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))-86400).lte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))+86399-24*3600));
        }else{
            criteria.andOperator(Criteria.where("time").gte(rechargeUserPeakEntity.getQTime().get(0).getTime()/1000-24*3600).lte(rechargeUserPeakEntity.getQTime().get(1).getTime()/1000-24*3600));
        }
        if(rechargeUserPeakEntity.getChannel()==null){
            criteria.orOperator(Criteria.where("channel").exists(false),Criteria.where("channel").is("total"));
        }else {
            criteria.and("channel").is(rechargeUserPeakEntity.getChannel());
        }
        query.addCriteria(criteria);
        query.with(Sort.by(Sort.Direction.ASC,new String[]{"time"}));
        List<RechargeUserPeakEntity> yestodayDataList=mongoTemplate.find(query, RechargeUserPeakEntity.class);
        //去重
        for (int i = 0; i < yestodayDataList.size() - 1; i++) {
            for (int j = yestodayDataList.size() - 1; j > i; j--) {
                long time =yestodayDataList.get(j).getTime();
                long time1=yestodayDataList.get(i).getTime();
                String quantum = yestodayDataList.get(j).getQuantum();
                String quantum1 = yestodayDataList.get(i).getQuantum();
                if(time==time1&&quantum.equals(quantum1)){
                    yestodayDataList.remove(j);
                }
            }
        }

        int[] yestodayData = new int[yestodayDataList.size()];
        for(int x=0;x<yestodayDataList.size();x++){
            RechargeUserPeakEntity rechargeUserPeakEntity1=yestodayDataList.get(x);
            yestodayData[x]=rechargeUserPeakEntity1.getNum();
        }

        //3日数据
        query = new Query();
        criteria = new Criteria();
        if(rechargeUserPeakEntity.getQTime()==null){
            criteria.andOperator(Criteria.where("time").gte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))-86400*3).lte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))+86399-24*3600*3));
        }else{
            criteria.andOperator(Criteria.where("time").gte(rechargeUserPeakEntity.getQTime().get(0).getTime()/1000-24*3600*3).lte(rechargeUserPeakEntity.getQTime().get(1).getTime()/1000-24*3600*3));
        }
        if(rechargeUserPeakEntity.getChannel()==null){
            criteria.orOperator(Criteria.where("channel").exists(false),Criteria.where("channel").is("total"));
        }else {
            criteria.and("channel").is(rechargeUserPeakEntity.getChannel());
        }
        query.addCriteria(criteria);
        query.with(Sort.by(Sort.Direction.ASC,new String[]{"time"}));
        List<RechargeUserPeakEntity> threeDataList=mongoTemplate.find(query, RechargeUserPeakEntity.class);
        //去重
        for (int i = 0; i < threeDataList.size() - 1; i++) {
            for (int j = threeDataList.size() - 1; j > i; j--) {
                long time =threeDataList.get(j).getTime();
                long time1=threeDataList.get(i).getTime();
                String quantum = threeDataList.get(j).getQuantum();
                String quantum1 = threeDataList.get(i).getQuantum();
                if(time==time1&&quantum.equals(quantum1)){
                    threeDataList.remove(j);
                }
            }
        }

        int[] threeData = new int[threeDataList.size()];
        for(int x=0;x<threeDataList.size();x++){
            RechargeUserPeakEntity rechargeUserPeakEntity1=threeDataList.get(x);
            threeData[x]=rechargeUserPeakEntity1.getNum();
        }

        //7日数据
        query = new Query();
        criteria = new Criteria();
        if(rechargeUserPeakEntity.getQTime()==null){
            criteria.andOperator(Criteria.where("time").gte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))-86400*7).lte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))+86399-24*3600*7));
        }else{
            criteria.andOperator(Criteria.where("time").gte(rechargeUserPeakEntity.getQTime().get(0).getTime()/1000-24*3600*7).lte(rechargeUserPeakEntity.getQTime().get(1).getTime()/1000-24*3600*7));
        }
        if(rechargeUserPeakEntity.getChannel()==null){
            criteria.orOperator(Criteria.where("channel").exists(false),Criteria.where("channel").is("total"));
        }else {
            criteria.and("channel").is(rechargeUserPeakEntity.getChannel());
        }
        query.addCriteria(criteria);
        query.with(Sort.by(Sort.Direction.ASC,new String[]{"time"}));
        List<RechargeUserPeakEntity> sevenDataList=mongoTemplate.find(query, RechargeUserPeakEntity.class);
        //去重
        for (int i = 0; i < sevenDataList.size() - 1; i++) {
            for (int j = sevenDataList.size() - 1; j > i; j--) {
                long time =sevenDataList.get(j).getTime();
                long time1=sevenDataList.get(i).getTime();
                String quantum = sevenDataList.get(j).getQuantum();
                String quantum1 = sevenDataList.get(i).getQuantum();
                if(time==time1&&quantum.equals(quantum1)){
                    sevenDataList.remove(j);
                }
            }
        }

        int[] sevenData = new int[sevenDataList.size()];
        for(int x=0;x<sevenDataList.size();x++){
            RechargeUserPeakEntity rechargeUserPeakEntity1=sevenDataList.get(x);
            sevenData[x]=rechargeUserPeakEntity1.getNum();
        }

        List<RechargeUserPeakEntity> xDataList = new ArrayList<>();

        int xDataSize=0;
        xDataSize=yestodayDataList.size();
        xDataList.addAll(yestodayDataList);
        String[] xData = new String[xDataSize];
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        for(int x=0;x<xDataList.size();x++){
            RechargeUserPeakEntity rechargeUserPeakEntity1=xDataList.get(x);
            String dateStr=null;
            if(rechargeUserPeakEntity.getQTime()==null){
                Date date = new Date();
                dateStr = sdf.format(date);
            }else{
                long time =rechargeUserPeakEntity1.getTime()+24*3600;
                Date date = new Date(time*1000);
                dateStr = sdf.format(date);
            }
            xData[x]=dateStr +" " +rechargeUserPeakEntity1.getQuantum();
        }


        Map map =new HashMap();
        map.put("content",list);
        map.put("totalElements",total);

        Map yDataMap = new HashMap();
        yDataMap.put("todayData",todayData);
        yDataMap.put("yestodayData",yestodayData);
        yDataMap.put("threeData",threeData);
        yDataMap.put("sevenData",sevenData);

        map.put("chartData",yDataMap);
        map.put("xData",xData);
        return map;
    }

    @Override
    public Map rechargeCount(RechargeCountPeakEntity rechargeCountPeakEntity, Pageable pageable) {
        String Qtime= DateUtil.timeStamp2Date(String.valueOf(new Date().getTime()/1000),"yyyy-MM-dd");
        Query query = new Query();
        query.skip((pageable.getPageNumber())*pageable.getPageSize());
        query.limit(pageable.getPageSize());
        Criteria criteria = new Criteria();
        if(rechargeCountPeakEntity.getQTime()==null){
            criteria.andOperator(Criteria.where("time").gte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))).lte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))+86399));
        }else{
            criteria.andOperator(Criteria.where("time").gte(rechargeCountPeakEntity.getQTime().get(0).getTime()/1000).lte(rechargeCountPeakEntity.getQTime().get(1).getTime()/1000));
        }
        if(rechargeCountPeakEntity.getChannel()==null){
            criteria.orOperator(Criteria.where("channel").exists(false),Criteria.where("channel").is("total"));
        }else {
            criteria.and("channel").is(rechargeCountPeakEntity.getChannel());
        }
        query.addCriteria(criteria);
        query.with(Sort.by(Sort.Direction.DESC,new String[]{"time"}));
        List<RechargeCountPeakEntity> list = mongoTemplate.find(query, RechargeCountPeakEntity.class);
        long total = mongoTemplate.count(query, RechargeCountPeakEntity.class);
        //去重
        for (int i = 0; i < list.size() - 1; i++) {
            for (int j = list.size() - 1; j > i; j--) {
                long time =list.get(j).getTime();
                long time1=list.get(i).getTime();
                String quantum = list.get(j).getQuantum();
                String quantum1 = list.get(i).getQuantum();
                if(time==time1&&quantum.equals(quantum1)){
                    list.remove(j);
                    total=total-1;
                }
            }
        }

        //今日数据
        query = new Query();
        criteria = new Criteria();
        if(rechargeCountPeakEntity.getQTime()==null){
            criteria.andOperator(Criteria.where("time").gte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))).lte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))+86399));
        }else{
            criteria.andOperator(Criteria.where("time").gte(rechargeCountPeakEntity.getQTime().get(0).getTime()/1000).lte(rechargeCountPeakEntity.getQTime().get(1).getTime()/1000));
        }
        if(rechargeCountPeakEntity.getChannel()==null){
            criteria.orOperator(Criteria.where("channel").exists(false),Criteria.where("channel").is("total"));
        }else {
            criteria.and("channel").is(rechargeCountPeakEntity.getChannel());
        }
        query.addCriteria(criteria);
        query.with(Sort.by(Sort.Direction.ASC,new String[]{"time"}));
        List<RechargeCountPeakEntity> todayDataList = mongoTemplate.find(query, RechargeCountPeakEntity.class);
        //去重
        for (int i = 0; i < todayDataList.size() - 1; i++) {
            for (int j = todayDataList.size() - 1; j > i; j--) {
                long time =todayDataList.get(j).getTime();
                long time1=todayDataList.get(i).getTime();
                String quantum = todayDataList.get(j).getQuantum();
                String quantum1 = todayDataList.get(i).getQuantum();
                if(time==time1&&quantum.equals(quantum1)){
                    todayDataList.remove(j);
                }
            }
        }


        int[] todayData = new int[todayDataList.size()];
        for(int x=0;x<todayDataList.size();x++){
            RechargeCountPeakEntity rechargeCountPeakEntity1=todayDataList.get(x);
            todayData[x]=rechargeCountPeakEntity1.getNum();
        }

        //昨日数据
        query = new Query();
        criteria = new Criteria();
        if(rechargeCountPeakEntity.getQTime()==null){
            criteria.andOperator(Criteria.where("time").gte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))-86400).lte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))+86399-24*3600));
        }else{
            criteria.andOperator(Criteria.where("time").gte(rechargeCountPeakEntity.getQTime().get(0).getTime()/1000-24*3600).lte(rechargeCountPeakEntity.getQTime().get(1).getTime()/1000-24*3600));
        }
        if(rechargeCountPeakEntity.getChannel()==null){
            criteria.orOperator(Criteria.where("channel").exists(false),Criteria.where("channel").is("total"));
        }else {
            criteria.and("channel").is(rechargeCountPeakEntity.getChannel());
        }
        query.addCriteria(criteria);
        query.with(Sort.by(Sort.Direction.ASC,new String[]{"time"}));
        List<RechargeCountPeakEntity> yestodayDataList=mongoTemplate.find(query, RechargeCountPeakEntity.class);
        //去重
        for (int i = 0; i < yestodayDataList.size() - 1; i++) {
            for (int j = yestodayDataList.size() - 1; j > i; j--) {
                long time =yestodayDataList.get(j).getTime();
                long time1=yestodayDataList.get(i).getTime();
                String quantum = yestodayDataList.get(j).getQuantum();
                String quantum1 = yestodayDataList.get(i).getQuantum();
                if(time==time1&&quantum.equals(quantum1)){
                    yestodayDataList.remove(j);
                }
            }
        }

        int[] yestodayData = new int[yestodayDataList.size()];
        for(int x=0;x<yestodayDataList.size();x++){
            RechargeCountPeakEntity rechargeCountPeakEntity1=yestodayDataList.get(x);
            yestodayData[x]=rechargeCountPeakEntity1.getNum();
        }

        //3日数据
        query = new Query();
        criteria = new Criteria();
        if(rechargeCountPeakEntity.getQTime()==null){
            criteria.andOperator(Criteria.where("time").gte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))-86400*3).lte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))+86399-24*3600*3));
        }else{
            criteria.andOperator(Criteria.where("time").gte(rechargeCountPeakEntity.getQTime().get(0).getTime()/1000-24*3600*3).lte(rechargeCountPeakEntity.getQTime().get(1).getTime()/1000-24*3600*3));
        }
        if(rechargeCountPeakEntity.getChannel()==null){
            criteria.orOperator(Criteria.where("channel").exists(false),Criteria.where("channel").is("total"));
        }else {
            criteria.and("channel").is(rechargeCountPeakEntity.getChannel());
        }
        query.addCriteria(criteria);
        query.with(Sort.by(Sort.Direction.ASC,new String[]{"time"}));
        List<RechargeCountPeakEntity> threeDataList=mongoTemplate.find(query, RechargeCountPeakEntity.class);
        //去重
        for (int i = 0; i < threeDataList.size() - 1; i++) {
            for (int j = threeDataList.size() - 1; j > i; j--) {
                long time =threeDataList.get(j).getTime();
                long time1=threeDataList.get(i).getTime();
                String quantum = threeDataList.get(j).getQuantum();
                String quantum1 = threeDataList.get(i).getQuantum();
                if(time==time1&&quantum.equals(quantum1)){
                    threeDataList.remove(j);
                }
            }
        }

        int[] threeData = new int[threeDataList.size()];
        for(int x=0;x<threeDataList.size();x++){
            RechargeCountPeakEntity rechargeCountPeakEntity1=threeDataList.get(x);
            threeData[x]=rechargeCountPeakEntity1.getNum();
        }

        //7日数据
        query = new Query();
        criteria = new Criteria();
        if(rechargeCountPeakEntity.getQTime()==null){
            criteria.andOperator(Criteria.where("time").gte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))-86400*7).lte(Integer.valueOf(DateUtil.date2TimeStamp(Qtime,"yyyy-MM-dd"))+86399-24*3600*7));
        }else{
            criteria.andOperator(Criteria.where("time").gte(rechargeCountPeakEntity.getQTime().get(0).getTime()/1000-24*3600*7).lte(rechargeCountPeakEntity.getQTime().get(1).getTime()/1000-24*3600*7));
        }
        if(rechargeCountPeakEntity.getChannel()==null){
            criteria.orOperator(Criteria.where("channel").exists(false),Criteria.where("channel").is("total"));
        }else {
            criteria.and("channel").is(rechargeCountPeakEntity.getChannel());
        }
        query.addCriteria(criteria);
        query.with(Sort.by(Sort.Direction.ASC,new String[]{"time"}));
        List<RechargeCountPeakEntity> sevenDataList=mongoTemplate.find(query, RechargeCountPeakEntity.class);
        //去重
        for (int i = 0; i < sevenDataList.size() - 1; i++) {
            for (int j = sevenDataList.size() - 1; j > i; j--) {
                long time =sevenDataList.get(j).getTime();
                long time1=sevenDataList.get(i).getTime();
                String quantum = sevenDataList.get(j).getQuantum();
                String quantum1 = sevenDataList.get(i).getQuantum();
                if(time==time1&&quantum.equals(quantum1)){
                    sevenDataList.remove(j);
                }
            }
        }

        int[] sevenData = new int[sevenDataList.size()];
        for(int x=0;x<sevenDataList.size();x++){
            RechargeCountPeakEntity rechargeCountPeakEntity1=sevenDataList.get(x);
            sevenData[x]=rechargeCountPeakEntity1.getNum();
        }

        List<RechargeCountPeakEntity> xDataList = new ArrayList<>();

        int xDataSize=0;
        xDataSize=yestodayDataList.size();
        xDataList.addAll(yestodayDataList);
        String[] xData = new String[xDataSize];
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        for(int x=0;x<xDataList.size();x++){
            RechargeCountPeakEntity rechargeCountPeakEntity1=xDataList.get(x);
            String dateStr=null;
            if(rechargeCountPeakEntity.getQTime()==null){
                Date date = new Date();
                dateStr = sdf.format(date);
            }else{
                long time =rechargeCountPeakEntity1.getTime()+24*3600;
                Date date = new Date(time*1000);
                dateStr = sdf.format(date);
            }
            xData[x]=dateStr +" " +rechargeCountPeakEntity1.getQuantum();
        }


        Map map =new HashMap();
        map.put("content",list);
        map.put("totalElements",total);

        Map yDataMap = new HashMap();
        yDataMap.put("todayData",todayData);
        yDataMap.put("yestodayData",yestodayData);
        yDataMap.put("threeData",threeData);
        yDataMap.put("sevenData",sevenData);

        map.put("chartData",yDataMap);
        map.put("xData",xData);
        return map;
    }
}
